package collection;

import java.util.ArrayList;
import java.util.List;

public class ListDemo3 {
    public static void main(String[] args) {
        List<Integer> list=new ArrayList<>();
        for(int i=0;i<10;i++){
            list.add(i*10);
        }
        System.out.println("list:"+list);

        List<Integer> sub=list.subList(3,7);
        System.out.println("sub:"+sub);

        for(int i=0;i<sub.size();i++){
            sub.set(i,sub.get(i)*10);//[100, 20, 30, 40, 50, 60, 70, 80, 90, 100]
        }
        System.out.println("sub:"+sub);//[100, 20, 30, 40, 50, 60, 70, 80, 90, 100]
        System.out.println("list:"+list);//[100, 20, 30, 100, 50, 60, 70, 80, 90, 100]

        list.set(3,1000);//修改原集合中下标为3的元素
        System.out.println("list:"+list);//[100, 20, 30, 100, 50, 60, 70, 80, 90, 100]
        System.out.println("sub:"+sub);//[100, 20, 30, 40, 50, 60, 70, 80, 90, 100]

        list.remove(0);//删除原集合中下标为0的元素
        System.out.println("list:"+list);//[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
        //原集合长度改变之后,子集不能再进行任何操作,若操作则发生异常,但是可以重新获取子集
        //System.out.println("sub:"+sub);
    }
}
